package xyf.p04.tree;

import commons.TreeNode;

/**
 * ClassName: M1712_BiNode
 * Description:
 * Author: xyf
 * Date: 9/9/22 9:43 AM
 * Version: 1.0
 **/
public class M1712_BiNode
{
    TreeNode dummyHead = new TreeNode(-1);

    TreeNode tail = dummyHead;

    public TreeNode convertBiNode(TreeNode root)
    {
        if (root == null)
        {
            return null;
        }

        dfs(root);

        return dummyHead.right;
    }

    private void dfs(TreeNode root)
    {
        if (root == null)
        {
            return;
        }

        dfs(root.left);

        tail.right = root;

        tail = root;

        tail.left = null;

        dfs(root.right);
    }
}